package com.ovhoo.vdm.vdm;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class VDMQuoteCommentsListAdapter extends BaseAdapter {
	private Activity context;
	protected VDMQuote quote = null;
	protected ArrayList<VDMQuoteComment> comments;
	private boolean inhibited;
	
	VDMQuoteCommentsListAdapter(Activity context) {
		this.context=context;
		this.inhibited = true;
	}
	
	
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater=context.getLayoutInflater();
		
		if (position == 0){	
			View _QuoteView = inflater.inflate(R.layout.quote, null);
			
			TextView message=(TextView)_QuoteView.findViewById(R.id.message);
			TextView author=(TextView)_QuoteView.findViewById(R.id.author);
			TextView agree=(TextView)_QuoteView.findViewById(R.id.agree);
			TextView deserved=(TextView)_QuoteView.findViewById(R.id.deserved);
			TextView category=(TextView)_QuoteView.findViewById(R.id.category);
						
			message.setText(this.quote.getMessage());
			author.setText(this.quote.getAuthor());
			agree.setText("" + this.quote.getAgree());
			deserved.setText("" + this.quote.getDeserved());
			category.setText(this.quote.getCategory());
			
			return(_QuoteView);
		}
		else{
			View _CommentView = inflater.inflate(R.layout.vdmquotecomments, null);
			
			
			
			TextView message=(TextView)_CommentView.findViewById(R.id.message);
			TextView author=(TextView)_CommentView.findViewById(R.id.author);
			
			VDMQuoteComment _comment = this.comments.get(position - 1);
			
			message.setText(_comment.getText());
			author.setText(_comment.getAuthor());

			
			return(_CommentView);
		}
		
	}

	@Override
	public int getCount() {
		if (this.inhibited || this.quote == null){
			return 0;
		}
		else if (this.comments == null){
			return 1;
		}
		return  1 + this.comments.size();
	}


	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	public void inhibit(boolean inhib){
		this.inhibited = inhib;
	}
	
	public void setQuote(VDMQuote quote){
		this.quote = quote;
		if(this.quote != null){
			this.comments = this.quote.getComments();
		}
		this.inhibit(false);
	}

	public void setQuotes(ArrayList<VDMQuote>  quotes){
		if (quotes != null){
			if (quotes.size() > 0){
				this.setQuote(quotes.get(0));
				this.inhibit(false);
			}
		}
		
	}
}
